using System;
using System.Collections.Generic;
using System.Linq;
namespace MicroMsg.Common.Event
{
	public class EventObject
	{
		public EventConst mID;
		public List<EventWatcher> listEventWatcher = new List<EventWatcher>();
		public BaseEventArgs args;
		public EventObject(EventConst eventConst_0)
		{
			this.mID = eventConst_0;
		}
		public bool addWatcher(EventWatcher eventWatcher)
		{
			if (eventWatcher == null || eventWatcher.mHandler == null)
			{
				return false;
			}
			if (this.listEventWatcher.Contains(eventWatcher))
			{
				return false;
			}
			this.listEventWatcher.Add(eventWatcher);
			return true;
		}
		public bool removeWatcher(EventWatcher eventWatcher)
		{
			return eventWatcher != null && this.listEventWatcher.Remove(eventWatcher);
		}
		public bool removeWatcher(EventHandlerDelegate eventHandler)
		{
			if (eventHandler == null)
			{
				return false;
			}
			EventWatcher eventWatcher = Enumerable.FirstOrDefault<EventWatcher>(Enumerable.Where<EventWatcher>(this.listEventWatcher, (EventWatcher eventWatcher_0) => eventWatcher_0.mHandler == eventHandler));
			return eventWatcher != null && this.listEventWatcher.Remove(eventWatcher);
		}
		public bool removeWatcher(string watherName)
		{
			if (string.IsNullOrEmpty(watherName))
			{
				return false;
			}
			EventWatcher eventWatcher = Enumerable.FirstOrDefault<EventWatcher>(Enumerable.Where<EventWatcher>(this.listEventWatcher, (EventWatcher eventWatcher_0) => eventWatcher_0.objName == watherName));
			return eventWatcher != null && this.listEventWatcher.Remove(eventWatcher);
		}
		public bool beginInvoke(BaseEventArgs evtArgs)
		{
			using (List<EventWatcher>.Enumerator enumerator = this.listEventWatcher.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					EventWatcher current = enumerator.get_Current();
					if (current != null)
					{
						current.beginInvoke(evtArgs);
					}
				}
			}
			return true;
		}
		public int getCount()
		{
			return this.listEventWatcher.get_Count();
		}
		public void printInfo()
		{
			string text = "";
			using (List<EventWatcher>.Enumerator enumerator = this.listEventWatcher.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					EventWatcher current = enumerator.get_Current();
					if (current != null)
					{
						text = text + current.objName + ":" + current.objMethod;
					}
				}
			}
		}
	}
}
